package org.example.my_netty.myNettyHandlerChain;

import org.example.my_netty.SocketChannelContext;

import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;

public class MyHandlerChain {
    //处理器链s
    List<MyNettyHandler> handlers = new ArrayList<>();


    //处理函数 就是遍历所有处理器 然后处理即可
    public void handle(SocketChannel channel, SocketChannelContext socketChannelContext) throws Exception {
        for (MyNettyHandler handler : handlers) {
            handler.handle(channel, socketChannelContext);
        }
    }


    //添加处理器
    public void addHandler(MyNettyHandler handler) {
        handlers.add(handler);
    }
}
